﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AForge.Genetic;

namespace dto
{
   public class doubleGriewankFct:IFitnessFunction 
    {
        double IFitnessFunction.Evaluate(IChromosome chromosome)
        {
            myDoubleArrayChromosome chromosome1 = (myDoubleArrayChromosome)chromosome;
            double functionValueGx = 0.0, functionValueHx = 1.0, chromosomeValue = 0.0;
            for (int i = 0; i < chromosome1.Length; ++i)
            {
                chromosomeValue = chromosome1.Value[i];
                functionValueGx += Math.Pow(chromosomeValue, 2.0);
                functionValueHx *= Math.Cos(chromosomeValue / Math.Sqrt(i + 1));
            }
            return (1 /((1 + (functionValueGx / (400 * chromosome1.Length)) - functionValueHx)));

        }
    }
}
